package com.example.wisdomclassroomapi.domain.repository;

import com.example.wisdomclassroomapi.domain.entity.GradeMajorSubjectBindEntity;
import com.example.wisdomclassroomapi.infrastructure.mapper.GradeMajorSubjectBindMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
/**
 * @Package: com.example.wisdomclassroomapi.domain.repository
 * @Description: <>
 * @Author: scholes
 * @CreateDate: 2022-04-19
 * @UpdateUser: scholes
 * @UpdateDate: 2022-04-19
 * @UpdateRemark: <>
 * @Version: 1.0
 */
@Repository
public class GradeMajorSubjectBindRepository {
    @Resource
    private GradeMajorSubjectBindMapper gradeMajorSubjectBindMapper;

    public void add(GradeMajorSubjectBindEntity entity) {
       gradeMajorSubjectBindMapper.insert(entity);
    }

    public GradeMajorSubjectBindEntity findById(String id) {
        return gradeMajorSubjectBindMapper.selectById(id);
    }

    public int updateById(GradeMajorSubjectBindEntity entity) {
        return gradeMajorSubjectBindMapper.updateById(entity);
    }

    public int deleteById(String id) {
        return gradeMajorSubjectBindMapper.deleteById(id);
    }

    public IPage<GradeMajorSubjectBindEntity> page(GradeMajorSubjectBindEntity entity,IPage page) {
        QueryWrapper<GradeMajorSubjectBindEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getSubjectId())){
            wrapper.eq("subject_id",entity.getSubjectId());
            }
            if (StringUtils.isNotBlank(entity.getMajorId())){
            wrapper.eq("major_id",entity.getMajorId());
            }
        return gradeMajorSubjectBindMapper.selectPage(page, wrapper);
    }

    public List<GradeMajorSubjectBindEntity> list(GradeMajorSubjectBindEntity entity) {
        QueryWrapper<GradeMajorSubjectBindEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getSubjectId())){
            wrapper.eq("subject_id",entity.getSubjectId());
            }
            if (StringUtils.isNotBlank(entity.getMajorId())){
            wrapper.eq("major_id",entity.getMajorId());
            }
        return gradeMajorSubjectBindMapper.selectList(wrapper);
    }

}